using System;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;

/// <summary>
/// 基础对话数据结构
/// </summary>
[System.Serializable]
public class DialogueLine
{
    public string speakerId;      // 说话者ID
    public string content;        // 对话内容
    public float displayTime;     // 显示时间（可选）
    public bool waitForInput;     // 是否等待输入
}


[System.Serializable]
public class DialogueChoice
{
    public string optionText;     // 选项文本
    public int nextNodeId;        // 选择后跳转的节点ID
    public string flagToSet;      // 选择后设置的标记（可选）
}

[System.Serializable]
public class DialogueNode
{
    public int id;                            // 节点ID
    public List<DialogueLine> dialogueLines;  // 对话内容
    public List<DialogueChoice> choices;      // 对话选项
    public string[] requiredFlags;            // 显示该节点需要的标记
}

// 对话数据SO
[CreateAssetMenu(fileName = "DialogueData", menuName = "Dialogue/DialogueData")]
public class DialogueDataSO : ScriptableObject
{
    public string dialogueId;
    public string description;
    public List<DialogueNode> nodes = new List<DialogueNode>();
    
    private Dictionary<int, DialogueNode> nodeDict;
    public void Initialize()
    {
        nodeDict = nodes.ToDictionary(node => node.id);
    }
    public DialogueNode GetNode(int id)
    {
        if (nodeDict == null)
        {
            return null;
        }
        DialogueNode node;
        return nodeDict.TryGetValue(id, out node) ? node : null;
    }
}